Page({
    data: {
        userInfo: null,
    },

    onLoad:function(){

    },


    logOff(){
        wx.showModal({
          title: '注销账号',
          placeholderText: '请输入密码',
          editable: true,
          success: (res) => {
            if (res.confirm) {
              let InPassword = res.content;
              let ThePassword = this.data.userInfo.password;
              if(ThePassword == InPassword){
                let that3 = this;
                wx.request({
                    url: 'http://47.95.223.130:8083/User/delete', // 这里需要替换为你的服务器实际 URL
                    
                    data: {
                        nickname: that3.data.userInfo.nickname,
                        password: ThePassword
                    },
                    method: 'POST',
                    header: {
                        'content-type': 'application/x-www-form-urlencoded'
                     },
                    success (res) {
                      if(res.data.code === 200) {
                            wx.removeStorageSync('userInfo');
                            console.log('清空了系统缓存“userInfo”');
                            // 刷新当前页面
                            var currentPage = getCurrentPages()[getCurrentPages().length - 1]
                            currentPage.onLoad();
                            console.log("已刷新页面");
                          
                      } else {
                        console.log('注销失败：' + res.data.message);
                      }
                    },
                    fail (err) {
                      console.log(err);
                    }
                  }); 
    
              } else {
                wx.showToast({
                  icon: 'error',
                  title: '密码错误',
                })
              }
                   
            }
          }
        })
      },
    
  })
  
  
  